create or replace function updateDepartmentType(
	out xml, inout xml
	)
as
$$
	declare
		-- alias is name for stored procedure parameters
		executeStatusData alias for $1;
		departmentTypeData	alias for $2;
		
		-- variable for node data
		vIdDepartmentType	integer := null;	-- department type id in data base
		vNameDepartmentType text	:= null;	-- department type name in data base
		
		-- node path
		vIdNode	varchar(100)	:= 	'/departmenttype/@id';
		vNameNode varchar(100)	:=	'/departmenttype/departmenttypename';
	begin
		-- get data from xml
		vIdDepartmentType := cast(extract_value(vIdNode, departmentTypeData) as integer);
		vNameDepartmentType := extract_value(vNameNode, departmentTypeData);
		
		-- insert data into trace table
		insert into DepartmentTypeTrace(idDepartmentType, nameDepartmentType, dateFrom)
			select depe.idDepartmentType, depe.nameDepartmentType, depe.dateFrom from DepartmentType depe
				where
					depe.idDepartmentType = vIdDepartmentType;
					
		-- update data into main table
		update DepartmentType
			set nameDepartmentType = vNameDepartmentType
			where
				idDepartmentType = vIdDepartmentType;
		
		-- return data
		executeStatusData := statusCall(successCode(), updateText()); 
		
		return;
	end;
$$ language plpgsql volatile;